package leetcode.link;




public class Test203 {
    public static void main(String[] args) {
        ListNode node = new ListNode(6);
        ListNode n2 = new ListNode(5,node);
        ListNode n3 = new ListNode(4,n2);
        ListNode n4 = new ListNode(3,n3);
        ListNode n5 = new ListNode(6,n4);
        ListNode n6 = new ListNode(2,n5);
        ListNode n7 = new ListNode(1,n6);
        ListNode node1 = removeElements(n7,6);
        while (node1.next != null){
            System.out.println(node1.val);
            node1 = node1.next;
        }
        System.out.println(node1.val);
    }

    public static ListNode removeElements(ListNode head, int val) {
        ListNode first = null;
        while (head.next != null){
            if (head.val != val && first == null){
                    first = head;
                }
            if (head.next.val == val){
            head = head.next.next;
        }
            else{
                head = head.next;
            }
            }
            return first;
    }
}
